package com.yoda.mall.mysql.api;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.mall.api.FlashPromotionApi;
import com.yoda.mall.model.entity.sms.Coupon;
import com.yoda.mall.model.entity.sms.FlashPromotion;
import com.yoda.mall.mysql.mapper.FlashPromotionMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class FlashPromotionApiImpl implements FlashPromotionApi {
    @Autowired
    private FlashPromotionMapper flashPromotionMapper;

    @Override
    public void createFlash(FlashPromotion flashPromotion) {
        flashPromotionMapper.insert(flashPromotion);
    }

    @Override
    public void deleteFlashById(Long id) {
        flashPromotionMapper.deleteById(id);
    }

    @Override
    public Page<FlashPromotion> getFlashPromotionListPage(String keyword, Integer pageNum, Integer pageSize) {
        Page<FlashPromotion> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<FlashPromotion> lqw = new LambdaQueryWrapper<>();
        lqw.like(StrUtil.isNotEmpty(keyword), FlashPromotion::getTitle, keyword);
        flashPromotionMapper.selectPage(page, lqw);
        return page;
    }

    @Override
    public void updateFlashPromotionStatus(FlashPromotion flashPromotion) {
        flashPromotionMapper.updateById(flashPromotion);
    }

    @Override
    public void updateFlashPromotion(FlashPromotion flashPromotion) {
        flashPromotionMapper.updateById(flashPromotion);
    }

    @Override
    public FlashPromotion getFlashPromotionById(Long id) {
        return flashPromotionMapper.selectById(id);
    }
}
